//
//  BaseResponse.m
//  LotteryClient
//
//  Created by SunYu on 14-2-6.
//  Copyright (c) 2014年 SunYu. All rights reserved.
//

#import "BaseResponse.h"
#import "JSONKit.h"

#define kDefaultErrorCode @""
#define kDefaultSucceedCode @"OK"

@implementation BaseResponse
DEF_STATIC_PROPERTY_INT(baseType, BaseTypeResponse)
- (id)init
{
	if (self = [super init])
	{
		_status = kDefaultErrorCode;
		_desc = @"";
		_resultStr = @"";
		return self;
	}
	return nil;

}

-(id)initWithResultData:(NSData *)data
{
    self = [self init];
    if (self)
	{
        NSString *jsonStr = [[NSString alloc] initWithBytes:[data bytes]
													 length:[data length]
												   encoding:NSUTF8StringEncoding];
		DLog(@"%@",jsonStr);
		@try
		{

			[self resetAllVarsByContent:jsonStr];
			self.resultStr = [jsonStr copy];

			if ([self.status isEqualToString:kDefaultSucceedCode])
			{
				self.success = YES;
			}
		}
		@catch (NSException *exception)
		{
			self.success = NO;
			self.desc = [NSString stringWithString:exception.description];
			DLog(@"%@",exception);

		}
		@finally
		{

		}
    }
    return self;
}



- (NSDictionary *)nameSwitchDictionary
{
	return [NSDictionary dictionaryWithObjectsAndKeys:@"status",@"rntCode",
			@"desc",@"rntMsg",
			@"object",@"responseParams",nil];
}

@end
